<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" @close="close">
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item label="文章标题" prop="articleTitle">
        <el-input v-model="form.articleTitle" placeholder="请输入职位内容" />
      </el-form-item>
      <el-form-item label="文章内容" prop="articleContent">
        <fuwenben v-model="form.articleContent" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { doEdit } from '@/api/xieyi'
  import fuwenben from '../../vab/editortwo/wang.vue'

  export default {
    name: 'UserManagementEdit',
    components: {
      fuwenben,
    },
    data() {
      return {
        form: {},
        rules: {
          articleTitle: [
            { required: true, trigger: 'blur', message: '请输入文章标题' },
          ],
          articleContent: [
            { required: true, trigger: 'blur', message: '文章内容不能为空' },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    methods: {
      showEdit(row) {
        this.title = '编辑'
        this.form = Object.assign({}, row)
        console.log(this.form)
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doEdit(this.form)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
